//--------------------Sonic CD HUD Script---------------------//
//--------Scripted by Christian Whitehead 'The Taxman'--------//
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//

// Aliases
// Not all of these are used here in the HUD script, some are just used as a way for other objects to globally transmit values
private alias Object.Value0 : Object.Timer     // Initially set via a loop in the UFO script
private alias Object.Value1 : Object.ToyBonnieTimer     // Initially set via a loop in the UFO script
private alias Object.Value3 : Object.ToyBonnieRandom    // Initially set via a loop in the UFO script
private alias Object.Value4 : Object.ToyBonnieAI    // Initially set via a loop in the UFO script
private alias Object.Value5 : Object.ScareTimer    // Initially set via a loop in the UFO script

private alias Object.Value6 : Object.ToyBonnieRise    // Initially set via a loop in the UFO script
private alias Object.Value7 : Object.MoveTime    // Initially set via a loop in the UFO script
private alias Object.Value8 : Object.HeadShake    // Initially set via a loop in the UFO script
private alias Object.Value9 : Object.Cooldown    // Initially set via a loop in the UFO script

private alias Object.Value10 : Object.SlideIn    // Initially set via a loop in the UFO script

private alias Object.Value11 : Object.Tweak    // Initially set via a loop in the UFO script

private alias Object[2].Value2 : Object.ScrollPos



// Game Mode Aliases
public value OfficePower = 100;

// Priority
private alias 1 : PRIORITY_ACTIVE

private alias 0 : CAM_SHOWSTAGE_0
private alias 1 : CAM_DININGHALL_1
private alias 2 : CAM_BACKSTAGE_2
private alias 3 : CAM_PIRATESCOVE_3
private alias 4 : CAM_WESTHALL_4
private alias 5 : CAM_CLOSET_5
private alias 6 : CAM_WHALLCORNER_6
private alias 7 : CAM_EASTHALL_7
private alias 8 : CAM_EHALLCORNER_8
private alias 9 : CAM_KITCHEN_9
private alias 10 : CAM_BATHROOMS_10

private alias 15 : ToyBonnie_OFFICEDOOR
private alias 16 : ToyBonnie_WAITTOSCARE
private alias 17 : ToyBonnie_SCARE


private alias object.state : ToyBonnie.State



event ObjectMain
//-1 is basically the ai level 0 ig
if Object[5].Type == TypeName[Blank Object]
	switch ToyBonnie.state
		case 0
			if object.Cooldown > 0
				object.Cooldown--
			end if	

			if object.Cooldown == 0
				Object.ToyBonnieTimer++
				Object.MoveTime = 500
				rand(temp3, 50)
				Object.MoveTime += temp3
				if Object.ToyBonnieTimer >= Object.MoveTime 
					Rand(Object.ToyBonnieRandom, 21)
					if Object.ToyBonnieAI > Object.ToyBonnieRandom 
						PlaySfx(SfxName[Stare], 0)	
						OfficeScary = 1
						object.state++
					end if
					Object.ToyBonnieTimer = 0
				end if	
			end if
		break
		case 1
			Object.ToyBonnieTimer++
			if Object.ToyBonnieTimer >= 100
				if MaskEquipped == 1
					if object.SlideIn > screen.xsize	
						CheckNotEqual(object[26].state, 1)
						temp1 = checkResult
						CheckNotEqual(object[19].state, 1)
						temp1 &= checkResult
						//withered foxy
						CheckNotEqual(object[21].state, 1)
						temp1 &= checkResult						
						if temp1 == 1
							StopSfx(SfxName[Stare])
							OfficeScary = 2
						end if
						object.Cooldown = 500
						Object.ToyBonnieTimer = 0
						Object.ScareTimer = 0
						object.state = 0
					else
						Object.SlideIn += 3
					end if
				else

					Object.ScareTimer++
					if Object.ScareTimer >= 300
						StopMusic()
						PlaySfx(SfxName[Scream2], 0)				
						Object.ScareTimer = 0			
						object.state = 17
					else
						temp0 = screen.xcenter	
						temp0 -= 50
						if object.SlideIn > temp0
							Object.SlideIn -= 2
						end if	
					end if	
				end if
			else
				Object.ScareTimer++
				if Object.ScareTimer >= 300
					StopMusic()
					PlaySfx(SfxName[Scream2], 0)				
					Object.ScareTimer = 0			
					object.state = 17
				else
					temp0 = screen.xcenter	
					temp0 -= 50
					if object.SlideIn > temp0
						Object.SlideIn -= 2
					end if	
				end if	
			end if	
			
			
		break
		case 17
			PlayerJumpscared = 1
			if Object.ToyBonnieRise > -100
				Object.ToyBonnieRise -= 16
			else
				Object.ToyBonnieRise = -100
			end if
		break			
	end switch
end if	
end event

event ObjectDraw

//	DrawNumbers(0, 32, 96, ToyBonnie.state, 3, 8, 0)

//	DrawNumbers(0, 64, 96, Object.ToyBonnieTimer, 3, 8, 0)
//
//	DrawNumbers(0, 96, 96, Object.ScareTimer, 3, 8, 0)



		rand(Object.HeadShake, 6)


	switch ToyBonnie.state
	case 1
		temp0 = Object.ScrollPos
		temp0 += Object.SlideIn

		Object.AnimationTimer += 128
		
		if Object.AnimationTimer > 239
			Object.AnimationTimer -= 240
			
			object.frame++
			if object.frame > 13
				object.frame = 12
			end if
		end if

		DrawSpriteScreenXY(object.frame, temp0, 20)	//body

	break
	case 17
		if Object.Tweak == 0
			temp0 = screen.xsize
			temp0 -= screen.xsize
			if Object[10].HeadShake > temp0
				Object[10].HeadShake -= 24
			else
				Object.Tweak = 1
			end if
		end if	


		temp1 = Screen.xsize
		temp1 /= 2
		temp1 -= 140


		temp1 += Object.HeadShake

		DrawSpriteScreenFX(10, FX_SCALE, temp1, Object.ToyBonnieRise)	//body
		DrawSpriteScreenFX(11, FX_SCALE, temp1, Object.ToyBonnieRise)	//head
	break
	end switch

	

end event


event ObjectStartup
	
	LoadSpriteSheet("FNAF/Jumpscares.gif")
	
	// Place the HUD object into reserved object slot 4 and initialise its values
	Object[25].Type = TypeName[ToyBonnie]
	
	// The object should always be run, regardless if it's within camera bounds or not
	Object[25].Priority = PRIORITY_ACTIVE
	
	// Make the HUD draw ontop of all other sprites, too
	Object[25].DrawOrder = 4

	Object[25].SlideIn = screen.xsize

	object[25].frame = 12

	Object[25].Cooldown = 500

	// 0-9 - Numbers 0-9
	SpriteFrame(0, 0, 8, 13, 558, 1)
	SpriteFrame(0, 0, 8, 13, 567, 1)
	SpriteFrame(0, 0, 8, 13, 576, 1)
	SpriteFrame(0, 0, 8, 13, 585, 1)
	SpriteFrame(0, 0, 8, 13, 594, 1)
	SpriteFrame(0, 0, 8, 13, 558, 15)
	SpriteFrame(0, 0, 8, 13, 567, 15)
	SpriteFrame(0, 0, 8, 13, 576, 15)
	SpriteFrame(0, 0, 8, 13, 585, 15)
	SpriteFrame(0, 0, 8, 13, 594, 15)

	
	SpriteFrame(18, 275, 248, 76, 1799, 529)
	SpriteFrame(42, 100, 200, 192, 1295, 129)	//11

	SpriteFrame(120, 30, 150, 209, 1897, 319)	//12
	SpriteFrame(121, 28, 148, 209, 1748, 319)	//13
end event


// ========================
// Editor events
// ========================

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	LoadSpriteSheet("3D_Test/Objects.gif")
	SpriteFrame(0, 0, 24, 16, 206, 58)

	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
